package itxx.itxx;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Map;

/*
* 获取请求数据的方法
* */
@WebServlet("/ServletDemo3")
public class ServletDemo3 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //根据名称获取数据
        String name = request.getParameter("name");
        System.out.println(name);
        System.out.println("--------------");

        //获取所有根据名称找到的值     针对复选框
        String[] names = request.getParameterValues("name");
        for (String s : names) {
            System.out.println(s);
        }
        System.out.println("--------------");

     //获取所有名称
        Enumeration<String> parameterNames = request.getParameterNames();
        while(parameterNames.hasMoreElements()){
            String sname = parameterNames.nextElement();
            System.out.println(sname);
        }
        System.out.println("--------------");

        //获取所有参数的键值对,
        Map<String, String[]> parameterMap = request.getParameterMap();
        for(String key:parameterMap.keySet()){
            String[] s = parameterMap.get(key);
            for (String s1 : s) {
                System.out.println(s1);
            }
        }


    }
}
